<? require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.php';

$events = new Events();
$eventsList = $events->getEvents();
?>

<div class="main">
    <div class="center">
        <ul class="menu">
            <li><a href="/index.php" class="btn ">Альбомы</a></li>
            <li><a href="/tv/all_events.php" class="btn btn-active">События</a></li>
        </ul>

        <div id="user-info" class="h">
            <span id="user-name"></span>
            <span id="user-lastname"></span>
        </div>
    </div>
    <div class="clear"></div>
    <fieldset><legend><h1>Все события</h1></legend></fieldset>
    <a href="add_event.php" class="btn add_button"><i class="ico">+</i>&nbsp;&nbsp;&nbsp;Добавление события</a>

    <? if ($events): ?>
    <ul class="events">
        <? $i = 0 ?>
        <? foreach ($eventsList as $event): ?>
        <? $i++ ?>
        <li <?= $i <= 3 ? 'class="wide"' : ''?> > <a href="edit_event.php?id=<?=$event['event_id']?>" class="img" style="background-image: url('<?=reset($event['photos'])?>');" title="Редактировать событие" ></a>
            <div class="desc" onmouseover="tooltip.getTooltip('<?=$event['event_id']?>', '<?=$event['event_author']?>', '<?=$event['event_count_rotate']?>', '<?=$event['event_date']?>')" onmouseout="tooltip.hideTooltip('<?=$event['event_id']?>')">

                <div class="title"><?= ($i <= 3) ? $event['event_name']: substr($event['event_name'], 0, 30) . '...'?></div>
                <div class="text">
                    <? if ($i <= 3): ?>
                        <?=$event['event_desc']?>
                    <? else: ?>
                        &nbsp;
                    <? endif ?>
                </div>
                <? if ($event['photos']):?>
                <div class="count-photos" >Фотографий в событии: <?=count($event['photos'])?></div>
                <?endif?>
				<div class="tooltip h" id="tooltip_<?=$event['event_id']?>"></div>
                <br>
                <div class="tools">
                    <? if ($event['event_rotate']): ?>
                        <span class="mark green-mark">ротируется</span>
                    <? endif ?>

                </div>
            </div>
        </li>
        <? endforeach ?>
    </ul>
    <div class="clear"></div>
    <? endif ?>

</div>
    <script type="text/javascript">
        var tooltip = {
            getTooltip: function (id, autor, count_rotate, date) {
                $('#tooltip_'+id).html('<span>Автор: '+autor+'</span><br><span>Количество показов: '+count_rotate+'</span><br><span>Дата: '+date+'</span><br>');
                $('#tooltip_'+id).show();
            },

            hideTooltip: function (id) {
                $('#tooltip_'+id).hide();
            }
        }

    </script>
<? require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.php'; ?>